package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;

/**
 * Created by Administrater on 2015/12/7.
 */
public class SureOrderStateTask extends CouponHttpBaseTask {
    private String mOrderNo;
    private String mPayChannel;

    public SureOrderStateTask(String orderNo) {
        super(TaskType.SURE_ORDER_STATE_TASK);
        mOrderNo = orderNo;
//        mPayChannel = payChannel;
    }

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject jsonObject = response.getBody();
        String status = null;
        if (jsonObject != null){
            status = jsonObject.getString("status");
        }
        notifyTaskCompleted(TaskResultCode.SUCCESS, status);
    }

    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if (mPhase == TASK_PHASE_INIT) {
            CouponHttpRequest request = new CouponHttpRequest(RequestType.SURE_ORDER_STATE_REQUEST);
            JSONObject json = new JSONObject();
            json.put("orderNo", mOrderNo);
//            json.put("payChannel", mPayChannel);
            request.setData(json.toString());
            request.setApiNo(ApiNo.SURE_ORDER_STATE);
            addRequest(request);
        }
    }
}
